package rs.ac.bg.etf.estudent.fragment;

import java.util.ArrayList;
import java.util.HashMap;

import rs.ac.bg.etf.estudent.R;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class ObligationFragment extends Fragment {
	
	private ListView not_done_list;
	private ListView done_list;
	private SimpleAdapter mNDTable, mDTable;
	private View mNotDoneView, mDoneView;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.fragment_obligation, container, false);
		
		not_done_list = (ListView)view.findViewById(R.id.not_done_table);
		mNotDoneView = view.findViewById(R.id.not_done_container);
		mDoneView = view.findViewById(R.id.done_container);
		View headerNotDoneView = inflater.inflate(R.layout.not_done_list_header, null, false);
		
		done_list = (ListView)view.findViewById(R.id.done_table);
		View headerDoneView = inflater.inflate(R.layout.done_list_header, null, false);
		not_done_list.addHeaderView(headerNotDoneView);
		done_list.addHeaderView(headerDoneView);
		
		Button done = (Button)view.findViewById(R.id.done_button);
		done.setOnClickListener(new Button.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mNotDoneView.setVisibility(View.GONE);
				mDoneView.setVisibility(View.VISIBLE);
			}
		});
		
		Button not_done = (Button)view.findViewById(R.id.not_done_button);
		not_done.setOnClickListener(new Button.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mDoneView.setVisibility(View.GONE);
				mNotDoneView.setVisibility(View.VISIBLE);
			}
		});
		return view;
	}
	
	@Override
	public void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		
		ArrayList<HashMap<String, String>> myNlist = new ArrayList<HashMap<String, String>>();
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("obaveza", "Neka obaveza");
		map.put("tipobaveze", "Neki tip obaveze");
		
		
		myNlist.add(map);
		// ...
		mNDTable = new SimpleAdapter(getActivity(), myNlist, R.layout.not_done_list_item,
		            new String[] {"obaveza","tipobaveze"}, new int[] {R.id.not_done_obl, R.id.not_done_type});
		not_done_list.setAdapter(mNDTable);
		
		ArrayList<HashMap<String, String>> myDlist = new ArrayList<HashMap<String, String>>();
				
		map.put("akronim","IR3AOR2");
		map.put("naziv", "Arhitektura i organizacija racunara 2");
		map.put("obaveza", "Laboratorijske vezbe");
		map.put("espb", "6");
		map.put("bodova","20");
		map.put("tip", "obavezna");
		map.put("datum", "1.5.2013");
		
		myDlist.add(map);
		
		mDTable = new SimpleAdapter(getActivity(), myDlist, R.layout.done_list_item, new String[]{"akronim", "naziv","obaveza","espb",
					"bodova","tip","datum"},new int[]{R.id.done_acronym, R.id.done_title, R.id.done_obl,R.id.done_espb,R.id.done_points,
						R.id.done_type, R.id.done_date});
		done_list.setAdapter(mDTable);
		
	}

}
